/*-------------------------------------------------------------------------------------------------------------------------
    The legendary PedoTrain
-------------------------------------------------------------------------------------------------------------------------*/
 
local PLUGIN = {}
PLUGIN.Title = "PedoTrain"
PLUGIN.Description = "I'm coming for you"
PLUGIN.Author = "Divran/Overv/Matt J"
PLUGIN.ChatCommand = "pedotrain"
PLUGIN.Usage = "[player] [time] [reason]"
PLUGIN.Privileges = { "pedotrain" }
 
function PLUGIN:Call( ply, args )
    if ( ply:EV_HasPrivilege( "pedotrain" ) ) then
        local players = evolve:FindPlayer( args, ply )
         
        for _, pl in ipairs( players ) do
            pl:SetMoveType( MOVETYPE_NONE )
            self:SpawnTrain( pl:GetPos() + pl:GetForward() * 1000 + Vector(0,0,50), pl:GetForward() * -1 )
        end
    end
    end
     
function PLUGIN:SpawnTrain( Pos, Direction )
    local train = ents.Create( "code_ent" )
    train:SetAngles( Direction:Angle() )
    train:SetPos( Pos )
    train:Spawn()
    train:Activate()
    train:EmitSound( "ambient/alarms/train_horn2.wav", 100, 100 )
    train:GetPhysicsObject():SetVelocity( Direction * 50000 )
     
    timer.Create( "TrainRemove_"..CurTime(), 5, 1, function( train ) train:Remove() end, train )
end
 
local MyCodeEnt = {}
  
MyCodeEnt.Type = "anim"
  
if SERVER then
    function MyCodeEnt:Initialize()
        self:SetModel("models/props_vehicles/train_boxcar.mdl")
        self:PhysicsInit(SOLID_VPHYSICS)
        self:SetSolid(SOLID_VPHYSICS)
    end
    function MyCodeEnt:StartTouch(ent)
        if ent:IsPlayer() then
            ent:ChatPrint("You got Touched by PedoTrain")
        end
    end
else
  
   function MyCodeEnt:Draw()
        self:DrawModel()
   end
  
end
scripted_ents.Register(MyCodeEnt, "code_ent", true)
 
function PLUGIN:Menu( arg, players )
    if ( arg ) then
        RunConsoleCommand( "ev", "pedotrain", unpack( players ) )
    else
        return "PedoTrain", evolve.category.punishment
    end
end
 
evolve:RegisterPlugin( PLUGIN )